package com.example.attendancesystem_1_8.MyContacts;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.attendancesystem_1_8.MyListAdapter;
import com.example.attendancesystem_1_8.R;
import com.example.attendancesystem_1_8.entity.Contacts;
import com.example.attendancesystem_1_8.entity.DakaTime;

import java.util.ArrayList;
import java.util.List;

public class ContactAdapter extends BaseAdapter
{
    private Context mcontext;
    private LayoutInflater mlayoutInflater;
    private List<Contacts> contactsList = new ArrayList<>();

    public ContactAdapter(List<Contacts> contactsList, Context context) {
        this.mcontext = context;
        this.contactsList = contactsList;
        mlayoutInflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return contactsList.size();
    }

    @Override
    public Object getItem(int position) {
        return contactsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    static class ViewHolder {
        public ImageView imageView;
        public TextView tvTitle, tvTime, tvContent;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ContactAdapter.ViewHolder holder = null;
        if (convertView == null) {
            convertView = mlayoutInflater.inflate(R.layout.layout_list_item, null);
            holder = new ViewHolder();
            holder.imageView = convertView.findViewById(R.id.iv);
            holder.tvTitle = convertView.findViewById(R.id.tv_title);
            holder.tvTime = convertView.findViewById(R.id.tv_time);
            holder.tvContent = convertView.findViewById(R.id.tv_content);
            convertView.setTag(holder);
        } else {
            holder = (ContactAdapter.ViewHolder) convertView.getTag();
        }
        //holder.imageView.setImageResource(R.drawable.picture1);
        holder.imageView.setImageResource(R.drawable.head_test);
        //holder.imageView.setImageResource(R.drawable.arrow_right);
        String ChartName = (contactsList.get(position).getUserName()) + "";
        holder.tvTitle.setText("姓名： \t" + ChartName);
        //list_setTime.get(position).getLeaderId()
        String ChartID = contactsList.get(position).getAccount();
        holder.tvTime.setText("工号：\t" + ChartID);
        //list_setTime.get(position).getHour() + "-" + list_setTime.get(position).getMinute()
        String ChartType = contactsList.get(position).getType() + "";
        holder.tvContent.setText("职位：\t" + ChartType);

        return convertView;
    }


}
